// 封装 axios请求
import axios from 'axios'
import qs from 'qs'
import {  createHashHistory } from 'history'
let history = createHashHistory();
const request = axios.create({
  baseURL: '/api/',
  timeout: 8000
})
// 拦截器
request.interceptors.request.use(function (config) {
 
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})
request.interceptors.response.use(function (res) {
	// 判断token过期
	if(res.data.code === '401'){
		// 跳转到登录
		localStorage.removeItem('userInfo')
		localStorage.removeItem('accessToken')
		history.push("/login")
	}
  return res
}, function (error) {
  return Promise.reject(error)
})
export default request
